package com.diyunapp.xilinapp.main;

/**
 * 欢迎页面
 * 通过SharedPreferences的方式判断是否是第一次运行
 * 1：第一次运行 通过发送handler信息的方式  提示Go.java跳转到GuideActivity
 * 2：如果不是 同样用发送handler信息的方式，提示Go.java在一定的时间后跳转到MainActivity
 * 内部判断是否用网络的方式加载欢迎页的图片
 * @author Administrator
 *
 */

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

import com.diyunapp.xilinapp.R;

public class Go extends Activity {
	private boolean isFirst = false;
	private static final int TIME = 3000;
	private static final int GO_HOME = 1500;
	private static final int GO_GUIDE = 1501;
	private SharedPreferences sp;
	
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case GO_HOME:
				goHome();
				break;
			case GO_GUIDE:
				goGuide();
				break;
			default:
				break;
			}
		};
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guideactivity);
		init();
	}

	private void init() {
		sp = getSharedPreferences("xilinshangchengSP", 1);
		isFirst = sp.getBoolean("isFirst", true);
		if(isFirst){
			handler.sendEmptyMessageDelayed(GO_GUIDE, TIME);
			sp.edit().putBoolean("isFirst", false).commit();
		}else{
			handler.sendEmptyMessageDelayed(GO_HOME, TIME);
		}
	}

	protected void goHome() {
		Intent intent = new Intent(Go.this, MainActivity.class);
		startActivity(intent);
		finish();
	}

	protected void goGuide() {
		Intent intent = new Intent(Go.this, GuideActivity.class);
		startActivity(intent);
		sp.edit().putBoolean("isLock", false).commit();
		finish();
	}
}
